﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ApiTemplateGenerate.TemplateTsAxios
{
    /// <summary>
    /// TS API方法模版
    /// 
    /// import service from '../../config'
    /// import link from '../../link'
    /// import* as common from '../../commonArgument'
    /// let ApiUrl = link.OAServiceX.APIService
    /// /**
    ///  * 分页获取数据
    ///  * @param pageIndex 当前页码
    ///  * @param pageSize 页大小
    ///  * @param startTime 开始时间
    ///  * @param endTime 结束时间
    ///  * @returns
    ///  */
    /// export const GetPageList = async(pageIndex: number, pageSize: number, startTime: number, endTime: number) => {
    ///   let responseData: any = await service({
    ///     url: ApiUrl + '/api/Versioninfo/GetPageList',
    ///     method: 'get',
    ///     params: { pageIndex: pageIndex, pageSize: pageSize, startTime: startTime, endTime: endTime }
    ///     })
    ///   let responseDataReturn: PageList<oa_versioninfo> = responseData
    ///   return responseDataReturn
    /// }
    /// </summary>
    public class TemplateMethod
    {
        public static string Template = @"
import service from '../../config'
import link from '../../link'
import * as common from '../../commonArgument'
let ApiUrl = link.OAServiceX.APIService
@foreach (var item in Model){
    if(!string.IsNullOrEmpty(@item.Describes)){<text>@item.Describes</text>}else{}
<text></text>
<text>export const @item.MethodName = async (@item.ParameterString) => {</text>
  <text>  let responseData : any = await service({</text>
    <text>    url: ApiUrl + '@item.ApiUrl',</text>
    <text>    method: '@item.RequestMethod',;</text>
 if(!item.IsNullParam){
         if(item.IsParams){
    <text>    params: @item.Params</text>
         }
         if(item.IsData){
    <text>    data: @item.Data</text>
         }
}
  <text>;  })</text>
  <text>  let responseDataReturn: </text><text>@item.ReturnValue = responseData
  return responseDataReturn</text>
<text>};</text>
}
";
    }
    public class TemplateMiniProgramMethod
    {
        public static string Template = @"
import { postJson }  from './request'
import link from './link'
const ApiUrl: string = ApiService.OAService.APIService
@foreach (var item in Model){
    if(!string.IsNullOrEmpty(@item.Describes)){<text>@item.Describes</text>}else{}
<text></text>
<text>export const @item.MethodName = async (@item.ParameterString) => {</text>
  <text>  let responseData : any = await postJson({</text>
    <text>    url: ApiUrl + '@item.ApiUrl',</text>
    <text>    method: '@item.RequestMethod',;</text>
 if(!item.IsNullParam){
         if(item.IsParams){
    <text>    params: @item.Params</text>
         }
         if(item.IsData){
    <text>    data: @item.Data</text>
         }
}
  <text>;  })</text>
  <text>  let responseDataReturn: </text><text>@item.ReturnValue = responseData
  return responseDataReturn</text>
<text>};</text>
}
";
    }
}
